﻿namespace ImageDupFinder.i18n
{
    using System.Globalization;

    /// <summary>
    /// Managment class for string internationalization (i18n)
    /// </summary>
    public class I18nManager
    {
        /// <summary>
        /// Class Singleton 
        /// </summary>
        private static I18nManager manager;

        /// <summary>
        /// Locking object provides thread safety.
        /// </summary>
        private static object syncRoot = new object();

        /// <summary>
        /// Initializes a new instance of the I18nManager class.
        /// </summary>
        protected I18nManager()
        {
        }

        /// <summary>
        /// Gets manager instance.
        /// </summary>
        public static I18nManager Manager
        {
            get
            {
                if (manager == null)
                {
                    lock (syncRoot)
                    {
                        if (manager == null)
                        {
                            manager = new I18nManager();
                        }
                    }
                }

                return manager;
            }
        }

        /// <summary>
        /// Get localized string.
        /// </summary>
        /// <param name="data">localized string id</param>
        /// <param name="culture">Culture info</param>
        /// <returns>loaclized string</returns>
        public string GetString(string data, CultureInfo culture)
        {
            return Strings.ResourceManager.GetString(data, culture);
        }

        /// <summary>
        /// Get localized string using current culture info.
        /// </summary>
        /// <param name="data">localized string id</param>
        /// <returns>localized string</returns>
        public string GetString(string data)
        {
            return this.GetString(data, CultureInfo.CurrentCulture);
        }
    }
}
